package com.checkchan.ethshare.util;

import com.checkchan.ethshare.env.Consts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;

@EnableConfigurationProperties(Consts.class)
public class Web3jClient {

//    @Autowired
//    private static Consts consts;

    private Web3jClient(){}

    private volatile static Web3j web3j;

    public static Web3j getClient(){
        if (web3j == null){
            synchronized (Web3jClient.class){
                if (web3j == null){
//                    web3j = Web3j.build(new HttpService(consts.getUrl()));
                    web3j = Web3j.build(new HttpService("HTTP://127.0.0.1:7545"));
                }
            }
        }
        return web3j;
    }
}
